#include <string>

#include "imageloadertest.h"
#include "../imageloader.h"
#include "../imageset.h"

#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <opencv/cxcore.h>
#include <opencv/cv.h>

using namespace std;
using namespace cshotel;
using namespace cv;
using namespace boost;
using namespace boost::filesystem;

/*
CppUnit::Test *ImageLoaderTest::suite() {
	CppUnit::TestSuite * suiteOfTests = new CppUnit::TestSuite( "ImageLoaderTest" );
  suiteOfTests->addTest( new CppUnit::TestCaller<ImageLoaderTest>( "testLoading", &ImageLoaderTest::testLoading ) );
	return suiteOfTests;
}
*/


int ImageLoaderTest::imageSetSize(shared_ptr<ImageSet> imageSet) {
	return imageSet->getSize();
}

void ImageLoaderTest::setUp() {
}

void ImageLoaderTest::tearDown() {
  delete imgloader;
}

void ImageLoaderTest::testLoadingValid() {
    
  int num;
  string filename;
  imageNames.clear();
  for(num = 0; num < 5; num++) {
      filename = "../src/tests/images/";
      filename.append(lexical_cast<std::string>(num));
      filename.append(".jpg");
      imageNames.push_back(filename);
  }
  imgloader = new ImageLoader( imageNames );
  shared_ptr<ImageSet> imageSet;
  CPPUNIT_ASSERT_NO_THROW	( imageSet= imgloader->loadImages() );
  //	vector<shared_ptr<InputImage> > buildvect = *imagePointer.get();
  //	int size = (int) buildvect.size();
  CPPUNIT_ASSERT( ImageLoaderTest::imageSetSize(imageSet) == 5 );

}

void ImageLoaderTest::testLoadingInvalid() {
    
	imageNames.clear();
  imageNames.push_back("../src/tests/images/5.jpg");
    
  imgloader = new ImageLoader( imageNames );
  shared_ptr<ImageSet> imageSet;
  CPPUNIT_ASSERT_NO_THROW	( imageSet = imgloader->loadImages() );
  //	vector<shared_ptr<InputImage> > buildvect = *imagePointer.get();
  //	int size = (int) buildvect.size();
  CPPUNIT_ASSERT( ImageLoaderTest::imageSetSize(imageSet) == 0 );
    
}

void ImageLoaderTest::testLoadingMany() {
    
	int num, total = 1000;
  imageNames.clear();
  for(num = 0; num < total; num++) {
      imageNames.push_back("../src/tests/images/0.jpg");
  }
  
  imgloader = new ImageLoader( imageNames );
  shared_ptr<ImageSet> imageSet;
  CPPUNIT_ASSERT_NO_THROW	( imageSet = imgloader->loadImages() );
  CPPUNIT_ASSERT( ImageLoaderTest::imageSetSize(imageSet) == total );
    
}
